package com.nbgroup.web.user;

import com.nbgroup.entity.User;
import com.nbgroup.service.user.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.security.Principal;
import java.util.Map;

/**
 * Created by Hanh on 2018/8/16 0016.
 * 用户信息管理 跳转页面
 */
@Controller
public class UserController {
    @Autowired
    UsersService usersService;
    //列表(跳转)
    @RequestMapping(value = "/toUserPage", method = RequestMethod.GET)
    public String userPage(Map<String, Object> map,User user, Integer page, Integer pageSize,Principal principal) throws Exception {
        Page<User> users = usersService.findByPage(user,page,pageSize);
        map.put("datas", users);
        return "user/user_list";
    }
    //跳转到添加
    @RequestMapping(value = "/toUserAdd", method = RequestMethod.GET)
    public String toUserAdd(Map<String, Object> map, Principal principal) throws Exception {
        return "user/user_insert";
    }
    //跳转到修改
    @RequestMapping(value = "/toUserUpdate/{id}", method = RequestMethod.GET)
    public String toUserUpdate(Map<String, Object> map, Principal principal,@PathVariable("id") String id) throws Exception {
        User user = usersService.getInfoById(id);
        map.put("user",user);
        return "user/user_update";
    }
}
